<?php
session_start();

if(isset($_SESSION['loggedin'])){
	
	include 'mail.php';
	
	if(isset($_SESSION['isValidated'])){
		//GO SEND THAT SHIAT!
		if(isset($_POST['msg']) && isset($_POST['sub']) && isset($_POST['to'])){
			$_SESSION['msg'] = sendMail($_POST['to'],$_POST['msg'],$_POST['sub']);
			header("Location: index.php?mailmembers");
		}else{
			$_SESSION['msg'] = '<p id="error">Du mangler at udfylde noget...</p>';
			if(isset($_POST['msg'])){
				$_SESSION['mailMSG'] = $_POST['msg'];
			}
			if(isset($_POST['sub'])){
				$_SESSION['mailSUB'] = $_POST['sub'];
			}
			header("Location: index.php?mailmembers");
		}
	}
}else{
	header("Location: index.php");
}

function sendMail($to, $inMSG, $inSub){
	
	$header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n" . 'From: SOFA <sofa@sofa-it.dk>' . "\r\n" ;
	return mail((string)$to,(string)$inSub,(string)$inMSG,$header);
}
?>
